import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login'
import Home from '../components/Home'
import Index from '../components/Index'
import List from '../components/List'
import Inbound from "@/components/Inbound";
import Member from "@/components/Member";
import Dictionary from '@/components/Dictionary'
import Base from "@/components/Base";
import Category from "@/components/Category";
Vue.use(VueRouter)

const routes = [
  {path: '/', redirect: '/login'},
  {path: '/login', component: Login},
  {
    path: '/home',
    component: Home,
    redirect: '/index',
    children: [{path: '/index', component: Index}, {path: '/list', component: List},{path: '/inbound', component: Inbound},{path: '/member',component: Member},{path: '/dictionary',component: Dictionary},{path: '/category',component: Category},{path: '/base',component: Base}]
  }
];

const router = new VueRouter({
  routes
})
// 挂载路由导航守卫
router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next()
  const id = window.sessionStorage.getItem('id')
  if (!id) return next('/login')
  next()
})
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
export default router
